/// @tags: PersistedTrie
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

constexpr int maxn = 5e4 + 3, charset = 2, bit = 31;

int n;
int rt[maxn], a[maxn], p[maxn], pre[maxn], nxt[maxn];
int ch[maxn * (bit + 1)][charset], siz[maxn * (bit + 1)];

inline void insert(int &root, int lst, int x) {
  static int tcnt = 0;
  int cur = root = ++tcnt;
  for (int i = bit - 1; i >= 0; --i) {
    int c = (x >> i) & 1;
    ch[cur][c ^ 1] = ch[lst][c ^ 1];
    ch[cur][c] = ++tcnt;
    cur = tcnt;
    lst = ch[lst][c];
    siz[cur] = siz[lst] + 1;
  }
}

inline int query(int l, int r, int x) {
  int res = 0;
  for (int i = bit - 1; i >= 0; --i) {
    int c = (x >> i) & 1;
    if (siz[ch[r][c ^ 1]] > siz[ch[l][c ^ 1]]) res += 1 << i, c = c ^ 1;
    l = ch[l][c], r = ch[r][c];
  }
  return res;
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    p[i] = i;
    pre[i] = i - 1;
    nxt[i] = i + 1;
    insert(rt[i], rt[i - 1], a[i]);
  }
  std::sort(p + 1, p + n + 1, [](int lhs, int rhs) { return a[lhs] < a[rhs]; });
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int l = pre[p[i]], r = nxt[p[i]];
    nxt[l] = r, pre[r] = l;
    if (l != 0) ans = std::max(ans, query(rt[pre[l]], rt[r - 1], a[p[i]]));
    if (r != n + 1) ans = std::max(ans, query(rt[l], rt[nxt[r] - 1], a[p[i]]));
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4098 [HEOI2013] ALO.in", "r", stdin);
  freopen("P4098 [HEOI2013] ALO.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
